/**************************************************************************************
* Component of simpleRTJ regression tests.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Created by:
*       RTJ Computing
**************************************************************************************/
public class TestShort
{
    public static void test() throws Exception
    {
       //test overwrap
       short t = 32767-1;
       t++;
       if (t != 32767) throw new Exception("TS1");
       t++;
       if (t != -32768) throw new Exception("TS2");

       //shift tests
       t = 4;
       t = (short)(t << (short)1);
       if (t != 8) throw new Exception("TS3");

       t = (short)(t >> (short)2);
       if (t != 2) throw new Exception("TS4");

       //division test
       t = 4;
       if (t >> 1 != t / 2) throw new Exception("TS5");
       if (t / 3 != 1) throw new Exception("TS6");
       if (t / 5 != 0) throw new Exception("TS7");

       //multiplication test
       if (t << 2 != t * 4) throw new Exception("TS8");
       if (t * 3 != 12) throw new Exception("TS9");

       //modulus test
       if (t % 3 != 1) throw new Exception("TS10");
       if (t % 4 != 0) throw new Exception("TS11");
       if (t % 5 != 4) throw new Exception("TS12");

       //unsigned right shift test
       t = -1;
       if (t >>> 4 == t >> 4) throw new Exception("TS13");

       //cast test
       t = 4;
       if ((float)t != 4.0F) throw new Exception("TS14");
       if ((byte)t != (byte)4) throw new Exception("TS15");
       t = -1;
       if ((byte)t != (byte)0xff) throw new Exception("TS16");
       if ((int)t != (short)0xffffffff) throw new Exception("TS17");

       //addition test
       if (t + 1 != 0) throw new Exception("TS18");
       if (t + 2 != 1) throw new Exception("TS19");

       //subtraction test
       if (t - 1 != -2) throw new Exception("TS20");

       //bitoperations test
       t = 4;
       t = (short)(t & (short)5);
       if (t != 4) throw new Exception("TS21");
       t = (short)(t | (short)5);
       if (t != 5) throw new Exception("TS22");
       t = (short)(t ^ (short)9);
       if (t != 12) throw new Exception("TS23");

       //order of evaluation test
       t = 4;
       t = (short)((t + (short)2)/(short)3);
       if (t != 2) throw new Exception("TS24");
       t = (short)(t + t / (short)2);
       if (t != 3) throw new Exception("TS25");
       t = (short)((t + (short)1) * (short)2);
       if (t != 8) throw new Exception("TS26");
       t = (short)(t - t/(short)2);
       if (t != 4) throw new Exception("TS27");
       t = (short)((short)2 << t / (short)4);
       if (t != 4) throw new Exception("TS28");
       t = (short)(t & (short)4 << (short)2 / (short)4);
       if (t != 4) throw new Exception("TS29");
       t = (short)(t | (short)5 << (short)2 / (short)4);
       if (t != 5) throw new Exception("TS30");

       //assignment
       t = 9;
       t += (t=3);
       if (t != 12) throw new Exception("TS31");
       t = 9;
       t = (short)(t + (t = (short)3));
       if (t != 12) throw new Exception("TS32");
   }
}
